﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCNguoiDung.ascx.cs" Inherits="Viewer.NhomNguoiDung.UserControls.UCNguoiDung" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:XScript ID="XScript1" runat="server">
    <script type="text/javascript">
        var addRow = function(record,store1,store2) {
        store1.remove(record);
        store2.add(record);

        };
       
        function AddNguoiDung(grid, store1, store2) {
            var records = grid.getSelectionModel().selections.items;
            var i = 0;
            for (i = 0; i < records.length; ) {
                addRow(records[i], store1, store2);
            }
            store2.sort('TenDangNhap', 'ASC');
           #{windowNguoiDung}.hide();
        }
        
        function SynDataBetween2Store()
        {
             Ext.each(#{storeNguoiDung_NhomNguoiDung}.data.items, function(record) {
                    var recordNeedToRemoved = #{storeNguoiDung}.getById(record.id);
                    if (recordNeedToRemoved != null) {
                        #{storeNguoiDung}.remove(recordNeedToRemoved);
                    }
                });
        }
        
        
  </script>
</ext:XScript>
<ext:Window ID="windowNguoiDung" runat="server" Modal="true" Width="500" AutoHeight="true" Closable="false"
    Title="Thêm Người Dùng" Hidden="true" Resizable="false" Icon="UserAdd" >
    <Items>
        <ext:GridPanel ID="grdNguoiDung" runat="server" Height="400" AutoExpandColumn="TenDangNhap">
            <Store>
                <ext:Store ID="storeNguoiDung" runat="server">
                    <Reader>
                        <ext:JsonReader IDProperty="NguoiDungID">
                            <Fields>
                                <ext:RecordField Name="TenDangNhap" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel>
                <Columns>
                    <ext:Column Header="Tên Đăng Nhập" DataIndex="TenDangNhap" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" HideCheckAll="true">
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" PageIndex="1" />
            </BottomBar>
        </ext:GridPanel>
    </Items>
        <TopBar>
        <ext:Toolbar ID="Toolbar1" runat="server">
            <Items>
                <ext:TriggerField ID="txtFilter12" runat="server" EnableKeyEvents="true" EmptyText="Nhập tên">
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <KeyUp Handler="this.triggers[0].show();applyFilter12(#{grdQUNguoiDung});" Buffer="350" />
                        <TriggerClick Handler="this.setValue(''); this.triggers[0].hide(); #{storeNguoiDung}.clearFilter();" />
                    </Listeners>
                </ext:TriggerField>
                <ext:Button ID="btnReload" runat="server" Text="Tải lại dữ liệu" Icon="Reload">
                    <Listeners>
                        <Click Handler="#{DirectMethods}.ReloadData();" />
                    </Listeners>
                </ext:Button>
            </Items>
        </ext:Toolbar>
    </TopBar>
    <Buttons>
        <ext:Button ID="btnAdd" runat="server" Text="Lưu" Width="60" Icon="UserAdd">
            <Listeners>
                <Click Handler="AddNguoiDung(#{grdNguoiDung},#{storeNguoiDung},#{storeNguoiDung_NhomNguoiDung});" />
            </Listeners>
        </ext:Button>
        <ext:Button ID="btnCancel" runat="server" Text="Đóng" Width="60" Icon="Cancel">
            <Listeners>
                <Click Handler="#{windowNguoiDung}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>